<?php
error_reporting(0);
$isadmin=1;
include_once '../comm/config.php';
include '../comm/checkpostandget.php';
include 'check.php';
include_once('../comm/class_db.php');
include("../comm/Taoapi.php");
if($_POST["add"]!=""){
	$nick=$_POST["nick"];
	$uid=$_POST["uid"];
	$consumer_protection=$_POST["consumer_protection"];
	$sid=$_POST["sid"];
	$cid=$_POST["cid"];
	$title=$_POST["title"];
	$pic_path=$_POST["pic_path"];
	$item_score=$_POST["item_score"];
	$service_score=$_POST["service_score"];
	$delivery_score=$_POST["delivery_score"];
	$shop_click_url=$_POST["shop_click_url"];
	$fanxianlv=$_POST["fanxianlv"];
	$level=$_POST["level"];
	$type=$_POST["type"];
	$city=$_POST["city"];
	$created=$_POST["created"];
	$total_num=$_POST["total_num"];
	$good_num=$_POST["good_num"];
	$good=($good_num/$total_num)*100;
	$tuijian=''?'0':$_POST["tuijian"];
	$sj= time();
	$num=count_sql("shop","*", "nick='$nick'");
	if($num>=1){
		$row=array('nick'=>$nick,'uid'=>$uid,'consumer_protection'=>$consumer_protection,'sid'=>$sid,'cid'=>$cid,'title'=>$title,'pic_path'=>$pic_path,'item_score'=>$item_score,'service_score'=>$service_score,'delivery_score'=>$delivery_score,'shop_click_url'=>$shop_click_url,'fanxianlv'=>$fanxianlv,'level'=>$level,'type'=>$type,'city'=>$city,'created'=>$created,'total_num'=>$total_num,'good_num'=>$good_num,'addtime'=>$sj,'tuijian'=>$tuijian,'good'=>$good);
		sql_update("shop",$row,"nick","'$nick'");
		echo "<script language=javascript>alert('该店铺已经存在，更新成功！');location.href='tao_dpgl.php';</script>";
	}else{
		$row=array('nick'=>$nick,'uid'=>$uid,'consumer_protection'=>$consumer_protection,'sid'=>$sid,'cid'=>$cid,'title'=>$title,'pic_path'=>$pic_path,'item_score'=>$item_score,'service_score'=>$service_score,'delivery_score'=>$delivery_score,'shop_click_url'=>$shop_click_url,'fanxianlv'=>$fanxianlv,'level'=>$level,'type'=>$type,'city'=>$city,'created'=>$created,'total_num'=>$total_num,'good_num'=>$good_num,'addtime'=>$sj,'tuijian'=>$tuijian,'good'=>$good);
		sql_insert_one("shop", $row);
		echo "<script language=javascript>alert('该店铺收录成功！');location.href='tao_dpgl.php';</script>";
	}
}else{
	$nick=trim($_POST["nick"]);
	if($nick==""){$nick=trim($_GET["nick"]);}
	$Taoapi = new Taoapi;
	$Taoapi->method = 'taobao.shop.get';
	$Taoapi->fields = 'sid,cid,title,pic_path,shop_score';
	$Taoapi->nick = $nick;
	$TaobaoData = $Taoapi->Send('get','xml')->getArrayData();
	$Shop=$TaobaoData['shop'];
	$sid=$Shop["sid"];
	$cid=$Shop["cid"];
	$title=$Shop["title"];
	$pic_path=$Shop["pic_path"];
	$item_score=$Shop["shop_score"]["item_score"];
	$service_score=$Shop["shop_score"]["service_score"];
	$delivery_score=$Shop["shop_score"]["delivery_score"];

	$Taoapi->method = 'taobao.taobaoke.shops.convert';
	$Taoapi->fields = 'click_url,commission_rate';
	$Taoapi->sids = $sid;
	$Taoapi->nick = MYUSERNICK;
	$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
	$TaobaokeShop=$TaobaokeData['taobaoke_shops']['taobaoke_shop'];
	$shop_click_url=$TaobaokeShop["click_url"];
	$fanxianlv=$TaobaokeShop["commission_rate"];
	
	$Taoapi->method = 'taobao.user.get';
	$Taoapi->fields = 'seller_credit,type,location,created';
	$Taoapi->nick = $nick;
	$TaoData = $Taoapi->Send('get','xml')->getArrayData();
	$TaoUser=$TaoData['user'];
	$level=$TaoUser["seller_credit"]["level"];
	$uid=$TaoUser["uid"];
	$consumer_protection=$TaoUser["consumer_protection"];
	$type=$TaoUser["type"];
	$city=$TaoUser["location"]["city"];
	$created=$TaoUser["created"];
	$total_num=$TaoUser["seller_credit"]["total_num"];
	$good_num=$TaoUser["seller_credit"]["good_num"];
	$tuijian="999";
	$num=count_sql("shop","*", "nick='$nick'");
	if($num>=1){
		$row=sel_sql("shop","*", "nick='$nick'");
		$tuijian=$row["tuijian"];
		$msg="该店铺已经存在，显示数据已经根据API更新，保存操作将对店铺进行更新。";
	}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="main">
	<div id="topnav"><div class="titlebt">添加店铺</div></div>
	<div id="center">
<table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><form id="form1" name="form1" method="post" action="tao_dpgl_add_step2.php">
<br />
<table width="100%"  align="center" border=1 cellpadding=0 cellspacing=0 style="border-collapse: collapse" bordercolor="#DCEAF7">
                      <tr>
                        <td width="143" height="30" align="right"><strong>第二步：</strong></td>
                        <td height="30" colspan="3">&nbsp;<strong>保存店铺信息                       </strong></td>
                      </tr>
					   <tr>
                        <td height="30" align="right">卖家昵称：</td>
                        <td width="412" height="30">&nbsp;<input type="text" name="nick" class="btn3" style="width:200px;" value="<?=$nick?>" /></td>
                        <td width="163" align="right">店铺名称：</td>
				        <td width="546">&nbsp;<input type="text" name="title" class="btn3" style="width:250px;" value="<?=$title?>" /></td>
				      </tr>
					  <tr>
                        <td height="30" align="right">信用等级：</td>
                        <td height="30">&nbsp;<input type="text" name="level" class="btn3" style="width:100px;" value="<?=$level?>" /> <img src="../images/level_<?=$level?>.gif"></td>
                        <td height="30" align="right">店铺类别：</td>
                        <td height="30">&nbsp;<input type="text" name="type" class="btn3" style="width:150px;" value="<?=$type?>" />
                          C=普通卖家 B=淘宝商城 </td>
					  </tr>
					   <tr>
                        <td height="30" align="right">返现比率：</td>
                        <td height="30">&nbsp;<input type="text" name="fanxianlv" class="btn3" style="width:100px;" value="<?=$fanxianlv?>" /> %</td>
                        <td height="30" align="right">所在地：</td>
                        <td height="30">&nbsp;<input type="text" name="city" class="btn3" style="width:150px;" value="<?=$city?>" /></td>
				      </tr>
					   <tr>
                        <td height="30" align="right">评价总数：</td>
                        <td height="30">&nbsp;<input type="text" name="total_num" class="btn3" style="width:200px;" value="<?=$total_num?>" /></td>
                        <td height="30" align="right">好评总数：</td>
                        <td height="30">&nbsp;<input type="text" name="good_num" class="btn3" style="width:150px;" value="<?=$good_num?>" />
                          好评率：<?=$good_num?>÷<?=$total_num?>×100%=<?=round(($good_num/$total_num)*100,2)?>%</td>
				      </tr>
					  <tr>
                        <td height="30" align="right">商品描述评分：</td>
                        <td height="30">&nbsp;<input type="text" name="item_score" class="btn3" style="width:200px;" value="<?=$item_score?>" /></td>
                        <td height="30" align="right">开店时间：</td>
                        <td height="30">&nbsp;<input type="text" name="created" class="btn3" style="width:150px;" value="<?=$created?>" /></td>
					  </tr>
					   <tr>
                        <td height="30" align="right">服务态度评分：</td>
                        <td height="30">&nbsp;<input type="text" name="service_score" class="btn3" style="width:200px;" value="<?=$service_score?>" /></td>
                        <td height="30" align="right">&nbsp;</td>
                        <td height="30">&nbsp;</td>
				      </tr>
					  <tr>
                        <td height="30" align="right">发货速度评分：</td>
                        <td height="30">&nbsp;<input type="text" name="delivery_score" class="btn3" style="width:200px;" value="<?=$delivery_score?>" /></td>
                        <td height="30" align="right">排序：</td>
                        <td height="30">&nbsp;<input type="text" name="tuijian" class="btn3" style="width:150px;" value="<?php if($tuijian==""){echo "999";}else{echo $tuijian;}?>" /> 
                        数字越大越靠前</td>
					  </tr>
					  <tr>
                        <td height="99" align="right">店铺图片：</td>
                        <td height="99" colspan="3">&nbsp;
                        <a href="<?=$shop_click_url?>" target="_blank"><img src="http://logo.taobaocdn.com/shop-logo/<?=$pic_path?>" width="80" height="80" /></a> <a href="<?=$shop_click_url?>" target="_blank">进入店铺</a></td>
                      </tr>
					   <tr>
                        <td height="27" align="center">&nbsp;</td>
                        <td height="30" colspan="3">&nbsp;<input type="submit" name="add" value=" 保存店铺信息 " class="button" />
                         <input type="hidden" name="sid" value="<?=$sid?>" />
                         <input type="hidden" name="pic_path" value="<?=$pic_path?>" />
						 <input type="hidden" name="cid" value="<?=$cid?>" />
						 <input type="hidden" name="uid" value="<?=$uid?>" />
						 <input type="hidden" name="consumer_protection" value="<?=$consumer_protection?>" />
						 <input type="hidden" name="shop_click_url" value="<?=$shop_click_url?>" /> <font color="#FF0000"><?=$msg?></font></td>
					   </tr>
                    </table>
                  </form>
                  </td>
                </tr>
              </table>
</div>
</div>
</body>
</html>
